package per.sunmes.cl.g.data.cards;

import per.sunmes.cl.g.actor.Card;
import per.sunmes.cl.g.actor.Zone;
import per.sunmes.cl.g.data.CardEffect;
import per.sunmes.cl.g.i.CallBack;
import per.sunmes.cl.g.screen.GameScreen;
import per.sunmes.cl.g.sys.LM;
import per.sunmes.cl.g.sys.RandU;
import per.sunmes.cl.g.sys.U;

import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

public class CardEffect2 implements CardEffect {
	// 基本类型
	// 占领当前区域
	@Override
	public void effect(GameScreen gameScreen, Zone selfZone, Card cardSelf) {
		selfCardMoveLandEffect(gameScreen, selfZone, cardSelf, new CallBack() {
			@Override
			public void call() {
				selfZone.setCard(cardSelf);
				selfZone.setPlayer(cardSelf.getPlayer());
				
				for (int y = 0; y < LM.mapYCount; y++) {
					Zone zone = selfZone.getZoneMap()[selfZone.getZoneX()][y];
					zone.setPlayer(cardSelf.getPlayer());
					Card zCard = zone.getCard();
					if (zCard != null && zCard != cardSelf) {
						zone.setCard(null);
						zCard.addAction(Actions.sequence(Actions.parallel(
								Actions.moveBy(RandU.rand(-10, 10),
										RandU.rand(20, 30), 0.4f,
										Interpolation.sineIn), Actions
										.rotateTo(RandU.rand(-45, 45), 0.4f,
												Interpolation.sineIn)), Actions
								.fadeOut(0.2f), Actions.removeActor()));
					}
				}
			}
		});

		// ///
		gameScreen.delayActionExecuteNextRound(1f);
	}

	@Override
	public void preEffect(GameScreen gameScreen, Zone selfZone, Card cardSelf,
			Group previewGroup) {
		for (int y = 0; y < LM.mapYCount; y++) {
			Zone zone = selfZone.getZoneMap()[selfZone.getZoneX()][y];
			Image pic = U.image(cardSelf.getPlayer().getLandPicPath());
			previewGroup.addActor(pic);
			pic.getColor().a = 0.5f;
			U.center(pic, zone);
		}
	}

	@Override
	public boolean isCouldPutToZone(Zone zone) {
		return true;
	}

}
